<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ page import="com.beaut.project.util.StaticData" %>
<%@ include file="/public/header.jsp"%>
<%
    String callback = request.getParameter("callback");
	String gd_id = request.getParameter("gd_id") == null ? "" : request.getParameter("gd_id");
	String dept_id = request.getParameter("dept_id") == null ? "" : request.getParameter("dept_id");
	String dept_name = request.getParameter("dept_name") == null ? "" : request.getParameter("dept_name");
	String gd_code = request.getParameter("gd_code") == null ? "" : request.getParameter("gd_code");
	String gd_name = request.getParameter("gd_name") == null ? "" : request.getParameter("gd_name");
	Map<String, Object> sessionMap = (Map<String, Object>) session.getAttribute("LOGIN_USER");
	String person_id = String.valueOf(sessionMap.get("id"));
	String person = String.valueOf(sessionMap.get("truename"));
	String is_closed = request.getParameter("is_closed");
%>
<html>
	<head>
		<title>班组还款管理</title>
			<link href="<%=contextPath%>/public/css/smart_wizard_vertical.css" rel="stylesheet"	type="text/css">
	
		<style>
			.td1{
				padding-top:10px;
				padding-bottom:5px;
				font-size: 12px;
				background-color: #c0ebd7;
				width:20%;
			}
			.td2{
				padding:5px;
			}
			.tdg{
			padding-top:10px;
			padding-bottom:5px;
			font-size: 12px;
			background-color: #c0ebd7;
			width:20%;
		}
		.tdb{
			padding:5px;
			width:30%;
		}
		</style>
	<script type="text/javascript">
	jQuery(document).ready(function() {
		jQuery("#searchValue").keypress(function(e) { 
	    	// 回车键事件 
	     	if(e.which == 13) { 
	     		 doSearch();
	       	} 
		});
		var fb_advances="";
		var param="gd_id=<%=gd_id%>";
		jQuery.ajax({
				type:'GET',
				url:'<%=contextPath %>/springMVC/gd/getGDContentByGDId',
				dataType:"JSON",
				data:param,
				success:function(rtJson){
					 fb_advances =rtJson.gd_worker_name;
				}
			});
		jQuery("#table").datagrid({
			title:"班组还款",
			iconCls:'icon-receive',
			loadMsg:'正在加载数据，请稍后......',
			url:'<%=contextPath %>/springMVC/gd/listGdYetAdvances?gd_id=<%=gd_id%>',
			rownumbers:true,
			fitColumns:true,
			nowrap:false,
			idField:'id',
			frozenColumns:[[
			     // {field:'ck',checkbox:true},
			      {title:'主键',field:'id',hidden:true},
			      {title:'是否还款',field:'yet',hidden:true}
			]],
			columns:[[
				{title:'班组',field:'fb_advances',width:100,align:'center',formatter:function(value,rowData,rowIndex){
					if(rowData.id!=''){
						return rowData.fb_advances=fb_advances;
					}
				
				}},
				{title:'日期',field:'operation_date',width:100,align:'center',sort:true},
				{title:'还款金额',field:'sum_money',width:100,align:'center'},
				{title:'当前状态',field:'status',width:60,align:'center',hidden:true},
				{title:'当前状态',field:'status_desc',width:60,align:'center'},
				{title:'经办人',field:'person_name',width:100,align:'center'},
				{title:'摘要',field:'remark',width:200,align:'center'},
				{title:'操作',field:'edit',width:100,align:'center',formatter:function(value,rowData,rowIndex){
					if(rowData.status == '<%=com.beaut.project.util.StaticData.NEW_CREATE%>'){
                    	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditYet(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='删除' onclick=\"javascript:deleteGDFinance('"+rowData.id+"');\"/>&nbsp;&nbsp;"
                    		  +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='提交确认' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
					}
					if(rowData.status == '<%=com.beaut.project.util.StaticData.NO_PASS%>'){
						return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditYet(1,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
						      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='提交确认' onclick=\"javascript:shenpi(this,'"+rowData.id+"');\"/>";
					}
                	return "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='查看' onclick=\"javascript:addOrEditYet(2,'"+rowData.id+"');\"/>&nbsp;&nbsp;"
				      +"<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.GD_ADVANCES_YET_SHENPI%>")+"','"+rowData.id+"');\"/>";

				}}
			]],
			view: detailview,
			detailFormatter:function(index,row){
				return '<div style="padding:2px"><table class="ddv"></table></div>';
			},
			onExpandRow: function(index,row){
				var yet_id = row.id;
				var ddv = $(this).datagrid('getRowDetail',index).find('table.ddv');
				 ddv.datagrid({
					title:'还款单明细',
					url:'<%=contextPath%>/springMVC/gd/listPageGdYetAdvancesDetail?voucher_id='+yet_id,
					loadMsg:'正在加载数据，请稍后......',
					fitColumns:true,
					rownumbers:true,
					frozenColumns:[[
								      {title:'主键',field:'id',hidden:true},
								      {title:'还款单id',field:'yet_id',hidden:true},
								      {title:'借款单id',field:'advances_id',hidden:true}
								]],
								columns:[[
									{title:'班组',field:'fb_advances',width:100,align:'center'},
									{title:'经办人',field:'person_name',width:100,align:'center'},
									{title:'欠款金额',field:'on_money',width:100,align:'center'},
									{title:'利率',field:'rate',width:100,align:'center'},
									{title:'还款金额',field:'yet_money',width:100,align:'center'},
									{title:'利息',field:'lxMoney',width:100,align:'center'}
					]],
					pageSize:10,
					pageList : [10,50,100],  
					pagination:true,
				 	onResize:function(){
				        $('#table').datagrid('fixDetailRowHeight',index);
				    },
				 	onLoadSuccess:function(){
				       setTimeout(function(){
				         $('#table').datagrid('fixDetailRowHeight',index);
				       },0);
				   }
				 });
				 $('#table').datagrid('fixDetailRowHeight',index);
			},
			pageSize:10,
			pageList : [10,50,100],  
			pagination:true,
			onLoadSuccess:function(rtJson){
				//预留状态判断，以后工单完工之后不允许修改。
				//if(""){
					//$("#add").hide();
					//$("#jdwc").hide();
				//}
				if(rtJson.rtState== '1')
				{
					$.messager.alert('提示',rtJson.rtMsrg);
				}
			}
		});
		
		
			  
			});
		
	  
	  function doSearch()
		{
			var searchValue = jQuery('#searchValue').val();
			jQuery('#table').datagrid('load',{
				searchValue:searchValue
			});
		}
		function addOrEditYet(type,id){
			if(type==0){
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditYetAdvances.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>",1000, 800);
			}else if(type==1){
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditYetAdvances.jsp?callback=rtCallBack&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&id="+id,1000, 800);
			}else {
				openDialogResize("<%=contextPath %>/springViews/gd/addOrEditYetAdvances.jsp?callback=rtCallBack&isShow=1&gd_id=<%=gd_id%>&dept_id=<%=dept_id%>&dept_name=<%=dept_name%>&gd_code=<%=gd_code%>&gd_name=<%=gd_name%>&id="+id,1000, 800);
			}
		}
		function rtCallBack(){
			$('#table').datagrid('reload');
		}
		function deleteRows(){
			var rows=jQuery('#table').datagrid('getSelections');
			var deleteVar="";
			if(rows.length==0)
			{
				jQuery.messager.alert('提示','选中要删除的记录');  
				return ;
			}
			for(var i=0;i<rows.length;i++)
			{
				if(i==(rows.length-1))
				{
					deleteVar+=rows[i].id;
				}else
				{
					deleteVar+=rows[i].id+",";
				}
			}
			jQuery.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					jQuery.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteGdYetAdvances",
						data:"ids="+deleteVar,
						dataType:"json",
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								jQuery.messager.alert('提示：',rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function deleteGDFinance(id){
			var rows=jQuery('#table').datagrid('getSelections');
			jQuery.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					jQuery.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/gd/deleteGdYetAdvances",
						data:"ids="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		function shenpi(obj,id){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	      var flowBusinessUrl="<%=contextPath %>/springViews/gd/addOrEditYetAdvances.jsp?callback=rtCallBack&isShow=1&id="+id;
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.GD_ADVANCES_YET_SHENPI%>")+"&businessId="+id;
	      jQuery(obj).hide();
	      jQuery.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							jQuery(obj).show();
						}
					});
	       
	    } 
		
		function doSearch() {
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			$('#table').datagrid('load', {
				start_time:start_time,
				end_time:end_time
			});
		}
	</script>
	</head>
	<body>
		
					
							<div id="table"  data-options="toolbar:'#tb',fit:true"></div>  
								<div id="tb" style="padding:3px;height:auto">
								<%if(!"1".equals(is_closed)){%>
								<div style="float:left;">
								<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditYet(0);">添加还款单</a>
							</div>
							<%}%>
						<div align="right">
							开始时间：<input id="start_time" name="start_time" class="easyui-datebox" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" />
								<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
						</div>
					</div>
	</body>
</html>